<?php 
defined( '_JEXEC' ) or die( 'Restricted access' ); 

jimport( 'joomla.application.component.model' ); 

class ModelSketchupsProject extends JModel 
{
	var $_project = null;  
	var $_comments = null;
	var $_id = null;

	
	function __construct()
	{
		global $mainframe;
		
				
		parent::__construct();
		
		$params =& $mainframe->getParams();
		$id = $params->get('id', 0);
		
		if(!$id)
		{
			$id = JRequest::getVar('id', '');
		}

		$this->_id = $id;
	}
	
	/**
	* Method to increment the hit counter for the item
	*
	* @access public
	* @return boolean True on success
	* @since 1.5
	*/
	function hit()
	{
	global $mainframe;

	 if ($this->_id)
 	 {
  	$item = & $this->getTable('sketchup');
  	$item->hit($this->_id);
  	return true;
  	}
  	return false;
  	}
	
	function getProject()
	{
		if(!$this->_project)
		{
			$query = "SELECT * FROM #__sketchup WHERE id = '". $this->_id . "'";
			$this->_db->setQuery($query);
			$this->_project = $this->_db->loadObject();
			
			if(!$this->_project->published)
			{
				JError::raiseError( 404, "Invalid ID provided" );
			}
		}
		
		
		return $this->_project;
	}
	
	function getComments()
	{
		if(!$this->_comments)
		{
			$query = "SELECT * FROM #__sketchup_comments WHERE sketchup_id = '" . $this->_id . "' ORDER BY comment_date";
			$this->_comments = $this->_getList($query, 0, 0);			
		}
		
		return $this->_comments;
	}
	
	
	function getTags()
	{
		if(!$this->_tags)
		{
			$query = "SELECT * FROM #__sketchup_tags WHERE sketchup_id = '" . $this->_id."' ORDER BY tag_date"; ;
			$this->_tags = $this->_getList($query, 0, 0);			
		}
		
		return $this->_tags;
	}
	
  

    
    

} //the end

?>